package com.andyage.admin.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.andyage.admin.bean.RoleBean;
import com.andyage.admin.dao.RoleMapper;
import com.andyage.admin.service.IRoleService;
import com.andyage.util.JsonContent;

import net.sf.json.JSONObject;
@Service
public class RoleServiceImpl implements IRoleService {
	@Resource
	private RoleMapper roleMapper;
	@Override
	public String queryRoleInfo(RoleBean roleBean) {
		List<RoleBean> list=roleMapper.queryRoleInfo(roleBean);
		int total=roleMapper.queryRoleInfoCount(roleBean);
		return JsonContent.getJsonArray(list, total);
	}

	@Override
	public String addRoleInfo(RoleBean roleBean) {
		int flag=roleMapper.addRoleInfo(roleBean);
		JSONObject json = new JSONObject();
		if (flag!=0) {
			json.accumulate("result", 1);
			json.accumulate("tips", "新增成功");
		} else {
			json.accumulate("result", 0);
			json.accumulate("tips", "新增失败");
		}

		return json.toString();
	}

	@Override
	public String updateRoleInfo(RoleBean roleBean) {
		int flag=roleMapper.updateRoleInfo(roleBean);
		JSONObject json = new JSONObject();
		if (flag!=0) {
			json.accumulate("result", 1);
			json.accumulate("tips", "修改成功");
		} else {
			json.accumulate("result", 0);
			json.accumulate("tips", "修改失败");
		}
		return json.toString();
	}

}
